package me.zhengjie.modules.inspection.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.inspection.domain.TInspectionTask;
import me.zhengjie.modules.inspection.service.TInspectionTaskService;
import me.zhengjie.modules.inspection.service.dto.TInspectionTaskQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author xuyukun
* @date 2019-07-21
*/
@RestController
@RequestMapping("api")
@SuppressWarnings({"unchecked","rawtypes"})
public class TInspectionTaskController {

    @Autowired
    private TInspectionTaskService tInspectionTaskService;

    //@Log("查询TInspectionTask")
	@GetMapping(value = "/tInspectionTask")
    @PreAuthorize("hasAnyRole('ADMIN','TINSPECTIONTASK_ALL','TINSPECTIONTASK_SELECT')")
    public ResponseEntity getTInspectionTasks(TInspectionTaskQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity(tInspectionTaskService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    
    @GetMapping(value = "/tInspectionTask/order")
    @PreAuthorize("hasAnyRole('ADMIN','TINSPECTIONTASK_ALL','TINSPECTIONTASK_SELECT')")
    public ResponseEntity getTInspectionTasksOrder(TInspectionTaskQueryCriteria criteria){
        return new ResponseEntity(tInspectionTaskService.queryAllWithOrder(criteria),HttpStatus.OK);
    }

    @Log("新增TInspectionTask")
    @PostMapping(value = "/tInspectionTask")
    @PreAuthorize("hasAnyRole('ADMIN','TINSPECTIONTASK_ALL','TINSPECTIONTASK_CREATE')")
    public ResponseEntity create(@Validated @RequestBody TInspectionTask resources){
        return new ResponseEntity(tInspectionTaskService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改TInspectionTask")
    @PutMapping(value = "/tInspectionTask")
    @PreAuthorize("hasAnyRole('ADMIN','TINSPECTIONTASK_ALL','TINSPECTIONTASK_EDIT')")
    public ResponseEntity update(@Validated @RequestBody TInspectionTask resources){
        tInspectionTaskService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除TInspectionTask")
    @DeleteMapping(value = "/tInspectionTask/{id}")
    @PreAuthorize("hasAnyRole('ADMIN','TINSPECTIONTASK_ALL','TINSPECTIONTASK_DELETE')")
    public ResponseEntity delete(@PathVariable Long id){
        tInspectionTaskService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}